import { resetRouter } from '@/router'

const state = {
  isLogin: 0, // 是否登录 1登录 0未登录
  userInfo: null, // 用户登录信息
}

const mutations = {
  SET_ISLOGIN: (state, isLogin) => {
    state.isLogin = isLogin
  },
  SET_USERINFO: (state, userInfo) => {
    state.userInfo = userInfo
  },
}

const actions = {
  login({ commit }, userInfo) {
    return new Promise((resolve, reject) => {
      commit('SET_ISLOGIN', 1)
      resolve()
    })
  },

  logout({ commit }, userId) {
    return new Promise((resolve, reject) => {
      commit('SET_ISLOGIN', 0)
      resetRouter();
      resolve()
    })
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}